﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpdateFoots : MonoBehaviour
{
	public GameObject LHip;
	public GameObject RHip;
	public float LeftHipZ;
	public float RightHipZ;
	public Transform LeftFoot;
	public Transform RightFoot;
	Vector3 LeftFootOffset;
	Vector3 RightFootOffset;
	// Start is called before the first frame update
	void Start()
	{
		//方向向量
		LeftFootOffset = (LeftFoot.position - LHip.transform.position).normalized;
		RightFootOffset = (RightFoot.position - RHip.transform.position).normalized;
		LeftHipZ = LHip.transform.rotation.eulerAngles.z;
		RightHipZ = RHip.transform.rotation.eulerAngles.z;
	}

	// Update is called once per frame
	void Update()
	{
		float angleLeft = Vector3.Angle(LeftFootOffset, (LeftFoot.position - LHip.transform.position));
		Quaternion angle = new Quaternion();
		angle.eulerAngles = new Vector3(0, 0, LeftHipZ - angleLeft);
		LHip.transform.rotation = angle;
		float angleRight = Vector3.Angle(RightFootOffset, (RightFoot.position - RHip.transform.position));
		angle.eulerAngles = new Vector3(0, 0, RightHipZ + angleRight);
		RHip.transform.rotation = angle;
	}
}
